package team.nmsg;

import java.util.ArrayList;
import java.util.Enumeration;

import org.springframework.boot.SpringApplication;

import team.nmsg.ge.system.util.ServerParams;

public class SysBootThread implements Runnable{

	public Integer syncInt = new Integer(1);
	
	private SysServerUI mainUI ;
	
	public String[] inputArgs ;
	
	public SysBootThread( SysServerUI mainUI ){
		this.mainUI = mainUI;
	}
	
	@Override
	public void run() {
	
		ServerParams.initServerParams();
		if( mainUI!=null ) {
			mainUI.initUI();
		}
		
		ArrayList<String> argList = new ArrayList<String>();
		if(  inputArgs !=null) {
			//调整输入参数
			for( int i=0; i<inputArgs.length ;i++ ){
				argList.add( inputArgs[i] );
			}
		}
		
		Enumeration<Object> keys = ServerParams.pros.keys();
		while(  keys.hasMoreElements() ){
			Object nextElement = keys.nextElement();
			String string = nextElement.toString();
			if( string.startsWith("__") ){
				String tmpNewArg = string.substring(2)+"="+ServerParams.pros.getProperty(string);
				argList.add(tmpNewArg);
			}
		}
		
		String[] argExt = new String[argList.size()];
		String[] array = argList.toArray(argExt);
		SpringApplication.run(SysSpringBoot.class,  array );

		
	}

	public void shutdownSystem() {
		
		System.exit(0);
		
	}

	public String[] getInputArgs() {
		return inputArgs;
	}

	public void setInputArgs(String[] inputArgs) {
		this.inputArgs = inputArgs;
	}
	

}
